{% extends 'base_user_center.html' %}
{% load static %}
{% block right_content %}
	<div class="right_content clearfix">
		{% csrf_token %}
		<h3 class="common_title2">全部订单</h3>
		{% for order in order_page %}
			<ul class="order_list_th w978 clearfix">
				<li class="col01">{{ order.create_time }}</li>
				<li class="col02">订单号：{{ order.order_id }}</li>
				<li class="col02 stress">{{ order.order_status_name }}</li>
			</ul>

			<table class="order_list_table w980">
				<tbody>
					<tr>
						<td width="55%">
							{% for goods in order.goods %}
								<ul class="order_goods_list clearfix">
									<li class="col01"><img src="{{ goods.sku.image.url }}"></li>
									<li class="col02">{{ goods.sku.name }}<em>{{ goods.price }}元/{{ goods.sku.unite }}</em></li>
									<li class="col03">{{ goods.count }}</li>
									<li class="col04">{{ goods.amount }}元</li>
								</ul>
							{% endfor %}
						</td>
						<td width="15%">{{ order.total_price|add:order.transit_price }}元(含运费)</td>
						<td width="15%">{{ order.order_status_name }}</td>
						<td width="15%">
							{% if not order.pay_method == 1 and order.order_status == 1 %}
								<a href="javascript:;"  data-id="{{ order.order_id }}" class="oper_btn">去付款</a>
							{% elif order.pay_method == 1 %}
								<a href="javascript:;"  class="">{{ order.pay_method_name }}</a>
							{% else %}
								<a href="javascript:;"  class="">已付款</a>
							{% endif %}
						</td>
					</tr>
				</tbody>
			</table>
		{% endfor %}

		<div class="pagenation">
			{% if order_page.has_previous %}
				<a href="{% url 'user:order' order_page.previous_page_number %}">&lt;上一页</a>
			{% endif %}
			{% for pindex in page_nums %}
				{% if pindex == order_page.number %}
					<a href="#" class="active">{{ pindex }}</a>
				{% else %}
					<a href="{% url 'user:order' pindex %}" >{{ pindex }}</a>
				{% endif %}
			{% endfor %}
			{% if order_page.has_next %}
				<a href="{% url 'user:order' order_page.next_page_number %}">下一页&gt;</a>
			{% endif %}

		</div>
	</div>
{% endblock right_content %}
{% block buttomfiles %}
	<script type="text/javascript" src="{% static 'js/jquery-1.12.4.min.js' %}"></script>
	<script type="text/javascript">
		$(".oper_btn").click(function(){
			var order_id = $(this).data("id");
			var token = $("input[name='csrfmiddlewaretoken']").val()
			var param = {
				order_id:order_id,
				csrfmiddlewaretoken: token
			}
			var page_num = $(".pagenation").find(".active").text()

			$.post("/order/pay", param, function(data){
				if(data.res==1){
					window.open(data.response_url)
					setTimeout(function(){
						$.post("/order/check", param, function(){
							if(data.res==1){
								alert("付款成功")
								location.reload()
							}else if(data.res==0){
								window.location.href = '/user/login?next=/user/order/' + page_num
							}else{
								alert(data.errmsg)
							}
						})
					},1000)

				}else if(data.res==0){
					window.location.href = '/user/login?next=/user/order/' + page_num
				}else{
					alert(data.errmsg)
				}
			})

		})

	</script>
{% endblock buttomfiles %}



